package com.cordershy.controller;

import com.cordershy.pojo.goal;
import com.cordershy.service.goalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
public class goalController {
    @Autowired
    goalService goalService;
    @RequestMapping("/goal/selectAll")
    public List<goal> selectAll(@RequestParam("username") String username){
        return goalService.selectAll(username);
    }
    @RequestMapping("/goal/deleteGoal")
    public void delete(@RequestParam(value = "goalid") int goalid){
        goalService.delete(goalid);
    }
    @RequestMapping("/goal/addGoal")
    public void add(goal goal){
        goalService.insert(goal);
    }
    @RequestMapping("/goal/updateGoal")
    public void update(goal goal){
        goalService.update(goal);
    }
//    @Scheduled(cron = "*/60  *  *  *  *  ?")
//    public void refresh(){
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
//        if(simpleDateFormat.format(new Date()).equals("00:00")){
//            for(int i=58;i<=60;i++){
//                goal goal = goalService.selectById(i);
//                if(goal!=null){
//                    goal.setGoalfinish("no");
//                    goalService.update(goal);
//                }
//            }
//        }
//    }
}
